<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    /* 
      Object.defineProperty
      定义一个对象的属性
    */
   var obj = {
     a: 10,
     b: 20
   }
   var a = 10;
   Object.defineProperty(obj, 'a', {
    //  架设一层拦截  getter拦截器 对于这个属性取值操作 setter拦截器 拦截对于属性赋值的操作
      get(){
        console.log('getter触发');
        return a;
      },
      set(val){
        console.log('setter触发', val);
        a = val;
      }
   })
   console.log(obj.a);
   obj.a = 100;
   console.log(obj.a);
  </script>
</body>
</html>